package com.plugin

import com.android.build.api.transform.QualifiedContent
import com.android.build.api.transform.Transform
import com.android.build.api.transform.TransformException
import com.android.build.api.transform.TransformInvocation
import com.google.common.collect.Sets
import org.gradle.api.Project

public class MyTransform extends Transform {
    private Project project

    public MyTransform(Project project) {
        this.project = project
    }

    //transform的名称
    //transformClassesWithMyClassTransformForDebug 运行时的名字
    //transformClassesWith + getName() + For + Debug或Release
    @Override
    String getName() {
        return "myTransform"
    }

    //需要处理的数据类型，有两种枚举类型
    //CLASSES和RESOURCES，CLASSES代表处理的java的class文件，RESOURCES代表要处理java的资源
    @Override
    Set<QualifiedContent.ContentType> getInputTypes() {
        return Collections.singleton(QualifiedContent.DefaultContentType.CLASSES)
    }

    //指Transform要操作内容的范围
    //PROJECT               Only the project content
    //SUB_PROJECTS          Only the sub-projects
    //EXTERNAL_LIBRARIES    Only the external libraries
    //TESTED_CODE           Code that is being tested by the current variant, including dependencies
    //PROVIDED_ONLY         Local or remote dependencies that are provided-only
    @Override
    Set<? super QualifiedContent.Scope> getScopes() {
        return Sets.immutableEnumSet(
                QualifiedContent.Scope.PROJECT,
                QualifiedContent.Scope.SUB_PROJECTS,
                QualifiedContent.Scope.EXTERNAL_LIBRARIES
        )
    }

    //指明当前Transform是否支持增量编译
    @Override
    boolean isIncremental() {
        return true
    }

    //覆写
    @Override
    void transform(TransformInvocation transformInvocation) throws TransformException, InterruptedException, IOException {
        super.transform(transformInvocation)
    }
}